package com.cat.dataStructure03;

import java.io.*;
import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://www.luogu.com.cn/problem/P4155
 * @create 2025/11/17 19:44
 * @since JDK17
 */

public class Solution81 {
    static int MAXN = 200001, LIMIT = 18, power;
    // 线段编号， 左边界， 右边界
    static int[][] line = new int[MAXN << 1][3], stjump = new int[MAXN << 1][LIMIT];
    static int[] ans = new int[MAXN];
    static int n, m;

    static void compute() {
        power = log2(n);
        build();
        for (int i = 1; i <= n; i++) {
            ans[line[i][0]] = jump(i);
        }
    }

    static int log2(int n) {
        int ans = 0;
        while ((1 << ans) <= (n >> 1)) {
            ans++;
        }
        return ans;
    }

    static void build() {
        for (int i = 1; i <= n; i++) {
            if (line[i][1] > line[i][2]) {
                line[i][2] += m;
            }
        }
        Arrays.sort(line, 1, n + 1,  (a, b) -> a[1] - b[1]);
        for (int i = 1; i <= n; i++) {
            line[i + n][0] = line[i][0];
            line[i + n][1] = line[i][1] + m;
            line[i + n][2] = line[i][2] + m;
        }
        int e = n << 1;
        for (int i = 1, arrive = 1; i <= e; i++) {
            while (arrive + 1 <= e && line[arrive + 1][1] <= line[i][2]) {
                arrive++;
            }
            stjump[i][0] = arrive;
        }
        for (int p = 1; p <= power; p++) {
            for (int i = 1; i <= e; i++) {
                stjump[i][p] = stjump[stjump[i][p - 1]][p - 1];
            }
        }
    }

    static int jump(int i) {
        int aim = line[i][1] + m, cur = i, next, ans = 0;
        for (int p = power; p >= 0; p--) {
            next = stjump[cur][p];
            if (next != 0 && line[next][2] < aim) {
                ans += 1 << p;
                cur = next;
            }
        }
        return ans + 2;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = (int) in.nval;
        in.nextToken();
        m = (int) in.nval;
        for (int i = 1; i <= n; i++) {
            line[i][0] = i;
            in.nextToken();
            line[i][1] = ((int) in.nval);
            in.nextToken();
            line[i][2] = ((int) in.nval);
        }
        compute();
        out.print(ans[1]);
        for (int i = 2; i <= n; i++) {
            out.print(" " + ans[i]);
        }
        out.println();
        out.flush();
        out.close();
        br.close();
    }
}
